/*
 * PS3Controller.cpp
 *
 *  Created on: Jan 24, 2015
 *      Author: mhealy
 */

#include <PS3Controller.h>
#include <WPILib.h>

#define xstr(s) str(s)
#define str(s) #s

const std::string PS3Controller::buttonNames_[NumButtons] = {
#define PS3_CONTROLLER_BUTTON(x)	str(x),
		PS3_CONTROLLER_BUTTONS
#undef PS3_CONTROLLER_BUTTON
};

PS3Controller::PS3Controller(Joystick* stick)
	: stick_(stick) {
	buttons_.reserve(NumButtons);
	for (int i = 0; i < NumButtons; ++i) {
		buttons_.push_back(new JoystickButton(stick, i+1));
	}
}

PS3Controller::~PS3Controller() {
	for (unsigned int i = 0; i < buttons_.size(); ++i) {
		delete buttons_[i];
		buttons_[i] = nullptr;
	}
}

bool PS3Controller::isButtonDown(Button b) {
	return buttons_[static_cast<unsigned int>(b)]->Get();
}
